package eecs285.proj4.gui;

import java.io.File;
import java.util.HashSet;

import javax.swing.filechooser.FileFilter;

public class EECSFileFilter extends FileFilter
{
  HashSet<String> acceptedExts;
  String descrip;

  // ---------------------------------------------------------------------------

  public EECSFileFilter(String inDescr)
  {
    descrip = inDescr;
    acceptedExts = new HashSet<String>();
  }// ctor

  // ---------------------------------------------------------------------------

  public void addExtension(String inExt)
  {
    acceptedExts.add(inExt);
  }// addExtenstion

  // ---------------------------------------------------------------------------

  public String getDescription()
  {
    return (descrip);
  }// getDescription

  // ---------------------------------------------------------------------------

  public boolean accept(File f)
  {
    boolean isAccepted = false;
    if( f.isDirectory() )
    {
      isAccepted = true;
    }
    else
    {
      int dotPos = f.getName().lastIndexOf('.');
      if( dotPos != -1 )
      {
        String extension = f.getName().substring(dotPos + 1);
        if( acceptedExts.contains(extension) )
        {
          isAccepted = true;
        }
      }
    }
    return (isAccepted);
  }// accept
}// EECSFileFilter

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

class MarkerboardFileFilter extends EECSFileFilter
{
  MarkerboardFileFilter()
  {
    super("Markerboard");
    addExtension("mkb");
  }// ctor
}// MarkerboardFileFilter

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

class ImageFileFilter extends EECSFileFilter
{
  ImageFileFilter()
  {
    super("PNG Image");
    addExtension("png");
  }// ctor
}// ImageFileFilter

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
